CommonUtils.regNamespace("com.im.fundPlanSet");

com.im.fundPlanSet.invoke = function() {

	//定义按钮
	var resetBtn;
	var saveBtn;
	var btnGetProject;
	var btn_getUnit;
	var btn_qryUnit;
	var btnQryProject;
	
	var client = new com.im.common.ajax();
	
	//初始化按钮
	var _initPageBtnToObj = function() {
		resetBtn = $("#btn_reset");
		saveBtn = $("#btn_save");
		btnGetProject = $("#btn_getProject");
		btnGetUnit = $("#btn_getUnit");
		btnQryUnit = $("#btn_qryUnit");
		btnQryProject = $("#btn_qryProject");
	}

	//按钮事件
	var _addBtnEvent = function() {
		//保存配置 
		saveBtn.click(function() {
			if (!validateParam()) {
				return;
			}
			var param = getParamsForJson();
			
			var result = client.callAsJson("fundPlanService/savePlandDeclareSet", param);
	        if (result.success) {
	            if(result.result != null){
	                //$('#userAddEditModal').modal('hide')
	                toastr.info("操作成功！");
	                //_doSearchPage(0,param);
	            }
	        } else {
	            toastr.error("服务器忙！请稍后再试！"+resust.resultMsg);
	        }
	        
		});

		resetBtn.click(function() {
			_reset();
		});

		btnGetProject.click(function(){
			var val = $("input[name='item']:checked").val();
			$("#projectName").val(val)
		});
		
		btnGetUnit.click(function(){
			var val = $("input[name='unit']:checked").val();
			$("#unitName").val(val)
		});
		
		btnQryUnit.click(function(){
			 
		});
		
		
		btnQryProject.click(function(){
			var projectParams = getProjectParams();
			var result = client.callAsJson("projectInfoService/queryImpleProjList", projectParams);
		});
		
	}
	var getProjectParams = function(){
		var projectParams = {};
		params.implePrjoName = $("#implePrjoName").val();
		params.developOrg = $("#developOrg").val();
		return projectParams;
	}
	
	//取得界面中所有的可填写可选择的参数
	var getParamsForJson = function() {
		var params = {};
		var fundPlanId = $("#fundPlanId").val();
		var fundPlanName = $("#fundPlanName").val();
		var projectName = $("#projectName").val();
		var statusCd = $("#statusCd").val();
		var description = $("#description").val();

		params.fundPlanId = fundPlanId;
		params.fundPlanName = fundPlanName;
		params.projectName = projectName;
		params.statusCd = statusCd;
		params.description = description;
		return params;
	}

	//校验参数
	var validateParam = function() {
		if (isEmpty('#fundPlanId') == "") {
			//toastr.info("请输入名称！");
			alert("请输入编号！");
			return false;
		}
		if (isEmpty('#fundPlanName') == "") {
			alert("请选择名称！");
			return false;
		}
		if (isEmpty('#projectName') == "") {
			alert("请选择项目！");
			return false;
		}
		if (isEmpty('#statusCd') == "") {
			alert("请输入状态！");
			return false;
		}
		return true;
	}

	//判断是否为空
	var isEmpty = function(c) {
		var reg = ($(c).val() != null && $(c).val() != ""
				&& $(c).val().trim() != null && $(c).val().trim() != "" && $(c)
				.val().trim() != -1) ? $(c).val().trim() : "";
		return reg;
	}

	function _reset() {
		$("#fundPlanNbr").val("");
		$("#fundPlanName").val("");
		$("#projectName").val("");
		$("#statusCd").val("");
		$("#description").val("");
	}

	var _init = function() {
		_initPageBtnToObj();
		_addBtnEvent();
	}

	return {
		init : _init
	}
}();

$(function() {
	com.im.fundPlanSet.invoke.init();
});